package drive.ReallController;

import drive.Model.Article;
import drive.Model.FavoriteRecord;
import drive.RealService.ArticleServiceC;
import drive.Service.ServiceInterface.ArticleService;
import drive.Service.ServiceInterface.FavoriteRecordService;
import drive.pojo.AdminAccess;
import lombok.experimental.Accessors;
import org.codehaus.jettison.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/Article")
public class ArticleControllerB {
    @Autowired
    ArticleServiceC articleServiceC;



    @PostMapping("/add")
    public String add(@RequestBody Article article,String img_url) throws JSONException, IOException {
        System.out.println(article);
        return articleServiceC.add(article,img_url);
    }

    @GetMapping("/detail")
    public String detail(int articleID){
        return articleServiceC.findById(articleID);
    }

    @GetMapping("/search")
    public String search(String keyword){
        return articleServiceC.search(keyword);
    }

    @PostMapping("/favorite")
    public String favorite(FavoriteRecord favoriteRecord){
        return articleServiceC.favorite(favoriteRecord);
    }



}
